channelEditJ.js ➔ onDrop   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 10
c 0
b 0
f 0
dl 0
loc 13
rs 9.9
1
var alerts = 0; 
2
$('#leftlayoutset' ).submit(
3
    function( e ) {
4
        var data = new FormData(this);
5
        jQuery.each(jQuery('#fileToUpload')[0].files, function(i, file) {
6
            data.append('file-'+i, file);
7
        });
8
9
        $.ajax( {
10
            url: '/post/channel_update_new',
11
            type: 'POST',
12
            data: data,
13
            cache: false,
14
            processData: false,
15
            contentType: false,
16
            success: function(result){
17
                alerts++;
18
                addAlert("editsuccess_" + alerts, "Successfully updated your channel!");
19
                showAlert("#editsuccess_" + alerts);
20
                console.log("DEBUG: " + result);
0 ignored issues
show
Debugging Code introduced by
console.log looks like debug code. Are you sure you do not want to remove it?
Loading history...
21
            }
22
        } );
23
        e.preventDefault();
24
    } 
25
);
26
27
function getData() {
28
    var layout = draggables2json();
29
30
    $.ajax({
31
    url: 'set_customization.php',
32
    method: 'POST',
33
    dataType: 'text',
34
    data: {
35
        layout: layout,
36
    },
37
    success: function(response) {
0 ignored issues
show
Unused Code introduced by
The parameter response is not used and could be removed.

This check looks for parameters in functions that are not used in the function body and are not followed by other parameters which are used inside the function.

Loading history...
38
        alert("Successfully updated your channel layout.");
0 ignored issues
show
Debugging Code Best Practice introduced by
The alert UI element is often considered obtrusive and is generally only used as a temporary measure. Consider replacing it with another UI element.
Loading history...
39
    }
40
    });
41
};
42
43
function onDragStart(event) {
44
  event
45
    .dataTransfer
46
    .setData('text/plain', event.target.id);
47
48
  event
49
    .currentTarget
50
    .style
51
    .backgroundColor = '#f2f2f2;';
52
}
53
54
function onDrop(event) {
55
  const id = event
56
    .dataTransfer
57
    .getData('text');
58
59
    const draggableElement = document.getElementById(id);
60
    const dropzone = event.target;
61
    dropzone.appendChild(draggableElement);
62
63
    event
64
    .dataTransfer
65
    .clearData();
66
}
67
68
function onDragOver(event) {
69
  event.preventDefault();
70
}
71
72
function draggables2json() {
73
  draggables = $("#layout").children();
0 ignored issues
show
Bug introduced by
The variable draggables seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.draggables.
Loading history...
74
  outj = {};
0 ignored issues
show
Bug introduced by
The variable outj seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.outj.
Loading history...
75
  for (di=0; di < draggables.length; di++) {
0 ignored issues
show
Bug introduced by
The variable di seems to be never declared. Assigning variables without defining them first makes them global. If this was intended, consider making it explicit like using window.di.
Loading history...
76
    outj[di] = draggables[di].textContent.replace(/\s+$/, '');
77
  }
78
  return JSON.stringify(outj);
79
}